FROM debian:8

RUN echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib\n\
  deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib\n\
  deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib\n\
  deb-src http://mirrors.163.com/debian/ jessie main non-free contrib\n\
  deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib\n\
  deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib\n\
  deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\n\
  deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib" \
  > /etc/apt/sources.list.new && cp -fr /etc/apt/sources.list.new /etc/apt/sources.list \
  && rm /etc/apt/sources.list.new

RUN apt-get update \
  && apt-get upgrade -y \
  && apt-get install -y curl make gcc g++ python \
  && apt-get clean

RUN cd /opt \
  && export node_version=v7.5.0 \
  && curl "http://npm.taobao.org/mirrors/node/${node_version}/node-${node_version}-linux-x64.tar.gz" -o node.tar.gz -L \
  && tar xvf node.tar.gz && rm node.tar.gz \
  && export PATH=$PATH:/opt/node-$node_version-linux-x64/bin \
  && npm config -g set registry "https://registry.npm.taobao.org" \
  && npm i -g node-gyp

ENV PATH $PATH:/opt/node-v7.5.0-linux-x64/bin

ADD . /var/www
RUN cd /var/www && npm i

ENTRYPOINT cd /var/www && npm run start && ./node_modules/.bin/pm2 log
